<template>
  <div class="login">
    <div class="login-form">
      <div class="title">
        组织架构登录
      </div>
      <div class="form-wrapper">
        <el-form ref="form" label-position="left" label-width="80px" :rules="rules" :model="form">
          <el-form-item label="用户名" prop="loginName">
            <el-input v-model="form.loginName"/>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input show-password v-model="form.password"/>
          </el-form-item>
        </el-form>
      </div>
      <div class="ctrl">
        <el-button type="primary" @click="handleLogin">登录</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import requests from "@/network/requests"

export default {
  name: "Login",
  data() {
    return {
      form: {
        loginName: "",
        password: "",
      },
      rules: {
        loginName: [
          {required: true, message: '请输入用户名', trigger: 'blur'}
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'}
        ]
      }
    }
  },
  methods: {
    handleLogin() {
      this.$refs.form.validate((flag) => {
        if (!flag) {
          this.$message.warning("请检查表单")
        } else {
          requests.post("/user/login", this.form).then(ret => {
            this.$store.dispatch("login", ret.data)
          })
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
.login{
  height: 100%;
  background: linear-gradient(45deg, skyblue, #eee);
  position: relative;
  .login-form{
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: 200px;
    width: 500px;
    background-color: white;
    box-shadow: 0 4px 4px #eee;
    border-radius: 1rem;
    padding: 8rem;
    .title {
      font-weight: 600;
      text-align: center;
    }
    .form-wrapper{
      margin-top: 2rem;
      padding: 4rem 0;
    }
    .ctrl{
      display: flex;
      justify-content: center;
    }
  }
}
</style>